<?php

namespace app\store\controller;
use app\store\model\Division as DivisionModel;
use think\Request;

class Division extends Controller
{
    public $model;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->model = new DivisionModel();
    }

    /**
     * 列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $list =  $this->model->getList();
        return show(self::SUCCESS, '操作成功', $list);
    }
    /**
     * 添加
     * @return array|mixed
     */
    public  function add(){
        $data = $this->request->param();
        if($this->model->save($data)){
            return show(self::SUCCESS,'操作成功');
        }else{
            return show(self::ERROR,'操作失败');
        }
    }
    /**
     * 更新
     * @param $article_id
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function edit($id)
    {
        $data = $this->request->param();
        if ($this->model->edit($data,$id)) {
            return show(self::SUCCESS,'操作成功');
        }
         return show(self::ERROR,'操作失败');
    }
    /**
     * 删除
     * @param $id
     * @return array
     * @throws \think\exception\DbException
     */
    public function delete($id){
        $result = DivisionModel::del($id);
        if($result){
            return show(self::SUCCESS,'操作成功');
        }
        return show(self::ERROR,'操作失败');
    }

    /**
     * 公司列表
     * @return array
     */
    public function companyList(){
        $list = getCompany();
        return show(self::SUCCESS, '操作成功', $list);
    }
}